using System.Timers;
using System.Windows.Input;
using PomodoroMinutes.Commadns;
using PomodoroMinutes.MVVMBase;

namespace PomodoroMinutes.Models
{
	public class MinutesViewModel : ViewModelBase
	{
		private int _remainingAngle;
		private int _remainingSeconds;
		private int _disturbanceCount;

		public MinutesViewModel()
		{

			AddDisturbanceCommand = new CommandAddDisturbanceCommand(this);
			_remainingSeconds = 25 * 60;
			_remainingAngle = 360;
			var timer = new Timer {Interval = 1000};
			timer.Elapsed += Timer_Elapsed;
			timer.Start();
		}

		private void Timer_Elapsed(object sender, ElapsedEventArgs e)
		{
			if (_remainingSeconds > 0)
			{
				_remainingSeconds--;
				RemainingTimeAngle = (int)((_remainingSeconds * 360) / (25.0 * 60.0));
			}
		}

		public int RemainingTimeAngle
		{
			get { return _remainingAngle; }
			set
			{
				_remainingAngle = value;
				NotifyPropertyChanged(() => RemainingTimeAngle);
			}
		}

		public ICommand AddDisturbanceCommand { get; private set; }

		public int DisturbanceCount
		{
			get { return _disturbanceCount; }
			set
			{
				_disturbanceCount = value;
				NotifyPropertyChanged(() => DisturbanceCount);
			}
		}
	}
}